package view
{
	import data.Globals;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.utils.getTimer;
	
	import view.base.ClearView;
	
	public class AnimationView extends ClearView
	{
		public static const COUNT_DOWN:String = "count_down";
		
		public static const ONE:String = "one";
		
		public static const TWO:String = "two";
		
		public static const THREE:String = "three";
		
		public static const NEXT_LEVEL:String = "next_level";
		
		private var count:CountDown;
		
		private var one:One;
		
		private var two:Two;
		
		private var three:Three;
		
		private var nextLevel:NextLevel;
		
		private var clip:MovieClip;
		
		private var callback:Function;
		
		public function AnimationView()
		{
			super();
			count = new CountDown();
			count.stop();
			
			one = new One();
			one.stop();
			
			two = new Two();
			two.stop();
			
			three = new Three();
			three.stop();
			
			nextLevel = new NextLevel();
			nextLevel.stop();

			this.x = Globals.stage_width/2;
			this.y = Globals.stage_height/2;
			
			this.mouseChildren = false;
			this.mouseEnabled = false;
		}
		private var useTime:Number;
		public function playClip(type:String,playEnd:Function = null):void{
		    getClip(type);
			callback = playEnd;
			if(clip){
				this.addChild(clip);
	    		useTime = getTimer();
				clip.addFrameScript(clip.totalFrames-1,remove);
				clip.play();
			}
		}
		
		private function getClip(type:String):void
		{
			switch(type){
				case COUNT_DOWN:
					clip = count;
					break;
				case ONE:
					clip = one;
	                break;
				case TWO:
					clip = two;
					break;
				case THREE:
					clip = three;
					break;
				case NEXT_LEVEL:
					clip = nextLevel;
					break;
			}
		}
		
		/**
		 *  
		 * @param waveNum 波数
		 * @return 
		 * 
		 */
		public static function getType(waveNum:int):String{
			var s:String;
			switch(waveNum){
				case 1:
					s = ONE;
					break;
				case 2:
					s = TWO;
					break;
				case 3:
					s = THREE;
					break;
			}
			return s;
		}
		
		
		private function remove():void{
			if(clip.parent)clip.parent.removeChild(clip);
			clip.gotoAndStop(0);
			if(callback != null)callback();
		}
	}
}